<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<div class="m-b-md">
    <form class="form-inline" role="form" id="searchForm" name="searchForm">
        <div class="form-group">
            <label class="control-label"> <span class="h4 font-thin v-middle">类型名称:</span></label>
            <input class="input-medium ui-autocomplete-input" id="name" name="dsgTypeFormMap.name">
        </div>
        <a href="javascript:void(0)" class="btn btn-default" id="search">查询</a>
    </form>
</div>
<header class="panel-heading">
    <div class="doc-buttons">
        <c:forEach items="${res}" var="key">
            ${key.description}
        </c:forEach>
    </div>
</header>
<div class="table-responsive">
    <div id="paging" class="pagclass"></div>
</div>

<div id="callback_div" class="table-responsive" style="display: none;">
    <div id="paging_callback" class="pagclass"></div>
</div>

<script>
    var pageii = null;
    var grid = null;
    $(function () {
        grid = lyGrid({
            id: 'paging',
            l_column: [{
                colkey: "id",
                name: "id",
                width: "50px",
                hide: true
            }, {
                colkey: "name",
                name: "类型"
            }, {
                colkey: "code",
                name: "编号"
            }, {
                colkey: "status",
                name: "状态",
                renderData: function (rowindex, data, rowdata, column) {
                    var str = "";
                    if (data == "1") {
                        str = "正常";
                    } else if (data == "2") {
                        str = "<span style='color: green;'>失效</span>";
                    }
                    return str;
                }
            }],
            jsonUrl: rootPath + '/dsg/type/findByPage.shtml',
            dymCol: true,
            checkbox: true
        });

        $("#search").click("click", function () {// 绑定查询按扭
            var searchParams = $("#searchForm").serializeJson();// 初始化传参数
            grid.setOptions({
                data: searchParams
            });
        });

        $("#addFun").click("click", function () {
            addFun();
        });
        $("#editFun").click("click", function () {
            editFun();
        });
        $("#delFun").click("click", function () {
            delFun();
        });
    });

    function editFun() {
        var cbox = grid.getSelectedCheckbox();
        if (cbox.length > 1 || cbox == "") {
            layer.msg("只能选中一个");
            return;
        }
        pageii = layer.open({
            title: "编辑",
            type: 2,
            area: ["800px", "60%"],
            content: rootPath + '/dsg/type/editUI.shtml?id=' + cbox
        });
    }

    function addFun() {
        pageii = layer.open({
            title: "新增",
            type: 2,
            area: ["800px", "60%"],
            content: rootPath + '/dsg/type/addUI.shtml'
        });
    }

    function delFun() {
        var cbox = grid.getSelectedCheckbox();
        if (cbox == "") {
            layer.msg("请选择删除项！！");
            return;
        }
        layer.confirm('是否删除？', function (index) {
            var url = rootPath + '/dsg/type/deleteEntity.shtml';
            var s = CommnUtil.ajax(url, {
                ids: cbox.join(",")
            }, "json");
            if (s == "success") {
                layer.msg('删除成功');
                grid.loadData();
            } else {
                layer.msg('删除失败');
            }
        });
    }

</script>
